<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

<%@ page import="com.conversationboard.config.*" %>
<%@ page import="com.conversationboard.model.StyleSheets"%>

<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>

<%@ page import="com.conversationboard.view.MainMenu"%>
<%@ page import="com.conversationboard.controller.confirm.Confirm"%>

<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>Cache Statistics</title>
		<link rel="stylesheet"title="Conversation Board" type="text/css" href="<%=Configuration.getInstance().getRoot()%>/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>">
	</head>

	<body>
	
		<%= MainMenu.display(request.getUserPrincipal()) %>
	
		<div class="headingblock">
			<h1>Conversation Board Cache Sizes</h1>
		</div>

		<div class="mainblock">

			<div class="formsectionlight">

				<h2>JVM Memory Usage</h2>
	
				<table class="table">
					
					<tr class="header">
						<td class="cell">Total Memory</td>
						<td class="cell">Used Memory</td>
						<td class="cell">Free Memory</td>
					</tr>			
				
					<tr class="row">
						<td class="cell"><fmt:formatNumber maxFractionDigits="2">${maxMemory/1000000}</fmt:formatNumber>M</td>
						<td class="cell"><fmt:formatNumber maxFractionDigits="2">${(totalMemory - freeMemory)/1000000}</fmt:formatNumber>M</td>
						<td class="cell"><fmt:formatNumber maxFractionDigits="2">${(maxMemory - (totalMemory - freeMemory))/1000000}</fmt:formatNumber>M</td>
					</tr>
					
				</table>

				<br />

				<form class="formsection" action="${contextPath}/Admin/AdminAdviseGCControllerServlet" method="post">
					<%= Confirm.getKey(request.getUserPrincipal().getName()) %>
				 	<input type="submit" value="    Advise Garbage Collection    " />
				</form>

				<br />
				
			</div>

			<br />

			<div class="formsectionlight">
				<h2>Caches</h2>
	
				<table class="table">
					
					<tr class="header">
						<td class="cell">Cache</td>
						<td class="cell">Size</td>
						<td class="cell">Elements</td>
					</tr>			
				
					<tr class="row">
						<td class="cell">Voter Cache</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="2">${voterCacheSize}</fmt:formatNumber>K</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="0">${voterCacheElements}</fmt:formatNumber></td>
					</tr>
					<tr class="row">
						<td class="cell">User Cache</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="2">${userCacheSize}</fmt:formatNumber>K</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="0">${userCacheElements}</fmt:formatNumber></td>
					</tr>
					<tr class="row">
						<td class="cell">Thread Title Cache</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="2">${threadTitleCacheSize}</fmt:formatNumber>K</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="0">${threadTitleCacheElements}</fmt:formatNumber></td>
					</tr>
					<tr class="row">
						<td class="cell">Thread Cache</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="2">${threadCacheSize}</fmt:formatNumber>K</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="0">${threadCacheElements}</fmt:formatNumber></td>
					</tr>
					<tr class="row">
						<td class="cell">Recent Message Cache</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="2">${recentMessageListSize}</fmt:formatNumber>K</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="0">${recentMessageListElements}</fmt:formatNumber></td>
					</tr>
					<tr class="row">
						<td class="cell">Banned User Cache</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="2">${bannedUserCacheSize}</fmt:formatNumber>K</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="0">${bannedUserCacheElements}</fmt:formatNumber></td>
					</tr>
					<tr class="row">
						<td class="cell">Ban Vote Cache</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="2">${banVoteCacheSize}</fmt:formatNumber>K</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="0">${banVoteCacheElements}</fmt:formatNumber></td>
					</tr>
					<tr class="row">
						<td class="cell">All New Answers Caches</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="2">${totalNewAnswersCacheSize}</fmt:formatNumber>K</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="0">${totalNewAnswersCacheElements}</fmt:formatNumber></td>
					</tr>
					<tr class="row">
						<td class="cell">Read Counter Cache</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="2">${readCounterCacheSize}</fmt:formatNumber>K</td>
						<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="0">${readCounterCacheElements}</fmt:formatNumber></td>
					</tr>
				</table>
				
				<p>Total cache size: <strong><fmt:formatNumber type="number" maxFractionDigits="2">${voterCacheSize + userCacheSize + threadTitleCacheSize + threadCacheSize + recentMessageListSize + bannedUserCacheSize + banVoteCacheSize + totalNewAnswersCacheSize}</fmt:formatNumber>K</strong></p>
	
				<br />

				<div class="formsectionlight">

					<h2>Search Engine</h2>
					
					<p><strong>Thread Searcher</strong>: <fmt:formatNumber type="number" maxFractionDigits="2">${threadSearcherSize}</fmt:formatNumber>K</p>
					<p><strong>Message Searcher</strong>: <fmt:formatNumber type="number" maxFractionDigits="2">${messageSearcherSize}</fmt:formatNumber>K</p>
				
				</div>
	
				<h2>New Answers Caches</h2>
	
				<table class="table">
					
					<tr class="header">
						<td class="cell">Board</td>
						<td class="cell">Size</td>
						<td class="cell">Elements</td>
					</tr>			
				
					<c:forEach var="newAnswersCache" items="${newAnswersCaches}">
						<tr class="row">
							<td class="cell">${newAnswersCache.key}</td>
							<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="2">${newAnswersCache.value[0]}</fmt:formatNumber>K</td>
							<td class="cell"><fmt:formatNumber type="number" maxFractionDigits="0">${newAnswersCache.value[1]}</fmt:formatNumber></td>
						</tr>
					</c:forEach>
					
				</table>
			</div>
		</div>
			
		<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
		<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 
		
	</body>
	
</html>
